<?php
/*  database_pool.inc

Copyright (C) 2011  Anthony Gaudino

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

include_once('includes/database/mysql_connection.inc');
include_once('includes/database/pgsql_connection.inc');
include_once('includes/database/sqlite_connection.inc');

class database_pool
{
    private $connection;

    public function connect($driver, $database, $username, $password, $host,
            $port, $collation)
    {
        if ($driver == 'mysql')
        {
            if ($port != '') $host = $host . ':' . $port;

            $this->connection = new mysql_connection();

            return $this -> connection -> connect($database, $username,
                    $password, $host, $collation);

        }
        else if ($driver == 'pgsql')
        {
            $this -> connection = new pgsql_connection();

            return $this -> connection -> connect("host=" . $host . " port=" .
                    $port . " dbname=" . $database . " user=" . $username .
                    " password=" . $password);
        }
        else if ($driver == 'sqlite')
        {
            $this -> connection = new sqlite_connection();

            return $this -> connection -> connect($database, $username,
                    $password, $host, $collation);
        }

        return false;
    }

    public function execute_query($query)
    {
        return $this -> connection -> execute_query($query);
    }

    public function disconnect()
    {
        return $this -> connection -> disconnect();
    }

    public function get_last_error()
    {
        return $this -> connection -> get_last_error();
    }

    public function get_connection()
    {
        return $this -> connection -> get_connection();
    }
}

?>